/**
 * 抓取远端API的结构
 * @param  {String} api    api 根地址
 * @param  {String} path   请求路径
 * @param  {Objece} params 参数
 * @return {Promise}       包含抓取任务的Promise
 */

module.exports = function (url, type, params) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: `${url}`,
      method: type,
      data: Object.assign({}, params),
      header: {
        'content-type': 'application/json',
        'Accept': 'application/json',
        'cookie': wx.getStorageSync('session')
      },
      success: function(data){
        if (data.errMsg == 'request:ok'){
          resolve(data.data)
        }
      },
      fail: reject
    })
  })
}
